package com.bw.liuyushan.liuyushan20210929.Utils;

import com.bw.liuyushan.liuyushan20210929.Requestaddress.API_Food;
import com.bw.liuyushan.liuyushan20210929.Requestaddress.API_User;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Retrofit;
import retrofit2.Retrofit.Builder;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Liuyushan20210929
 * file name is : RxJavaLoginManager
 * created by Ender on 2021/9/29 14:35.
 * author : 刘雨杉
 * Describe:
 */
public class RxJavaFoodManager {
    private static RxJavaFoodManager rxJavaFoodManager;

    public static RxJavaFoodManager getInstance() {
        if (rxJavaFoodManager==null){
            rxJavaFoodManager=new RxJavaFoodManager();
        }
        return rxJavaFoodManager;
    }
    private Retrofit retrofit;

    public Retrofit getRetrofit() {
        if (retrofit==null){
            retrofit=new Builder()
                    .baseUrl(API_Food.url)
                    .addConverterFactory(GsonConverterFactory.create())
                    .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                    .client(new OkHttpClient.Builder()//添加OKHttp网络拦截器
                            .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
                            .build())
                    .build();
        }
        return retrofit;
    }
}
